<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');

	class m_vendorprofile extends CI_Model
	{
		function __construct()
    	{
    	    // Call the Model constructor
    	    parent::__construct();
    	}
    	
    	function get_user_id($user_email)
    	{
			$this->load->database();
			$query = $this->db->get_where('tblVendorUser', array('userEmail' => $user_email));
			return $query;
    	}
    	
    	function get_profile($user_id)
    	{
			$this->load->database();
			$query = $this->db->select('*')->from('tblVendorUser')->join('tblVendorNames','tblVendorUser.userId = tblVendorNames.Vendor_ID', 'left')->join('tblVendorAddresses','tblVendorUser.userId = tblVendorAddresses.Vendor_ID', 'left')->join('tblVendorSources','tblVendorUser.userId = tblVendorSources.Vendor_ID', 'left')->where('tblVendorUser.userId', $user_id);
			$query = $this->db->get();
			return $query;
    	}
		
		function update_user_profile($user_profile)
		{
			$this->load->database();
			$sql = "REPLACE INTO tblVendorAddresses (Vendor_ID, Attention, Street_Address, City, State, Zip_Code) VALUES ('" . $user_profile['userId'] . "', '" . $user_profile['attention'] . "', '" . $user_profile['street'] . "', '" . $user_profile['city'] . "', '" . $user_profile['state'] . "', '" . $user_profile['zipCode'] . "')";
			$query = $this->db->query($sql);
			$sql = "REPLACE INTO tblVendorNames (Vendor_ID, Vendor_Name, Vendor_Website) VALUES ('" . $user_profile['userId'] . "', '" . $user_profile['name'] . "', '" . $user_profile['website'] . "')";
			$query = $this->db->query($sql);
			$sql = "REPLACE INTO tblVendorSources (Vendor_ID, Vendor_Source) VALUES ('" . $user_profile['userId'] . "', '" . $user_profile['source'] . "')";
			$query = $this->db->query($sql);
			return $query;
		}
	}
?>
